package zh.log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class ResultLog {
    public static void log(String time,String data) throws IOException {
        findLogDir();
        byte[] dataBytes = data.getBytes();
        String filePath = "./log/result_" + time + ".log";
        File file = new File(filePath);

        if(!file.exists()){
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        FileOutputStream fileOutputStream = new FileOutputStream(file, true);
        fileOutputStream.write(dataBytes);
        fileOutputStream.close();
    }

    private static void findLogDir(){
        File file = new File("./log");
        if (!file.exists() && !file.isDirectory()) {
            file.mkdir();
        }
    }
}

